#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QWidget>
#include <QTreeView>
#include <QMainWindow>
#include <QNetworkAccessManager>

#include "collectionitemmodel.h"
#include <qlistview.h>
#include <qtableview.h>

/*! This is the main window's track list view. It is in fact just a QListView
 * with some custom display properties.
 */
class ListViewWidget : public QTableView
{
public:
    ListViewWidget();

protected:
    void mousePressEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    void leaveEvent(QEvent* event );

private:
    QDrag* drag;
};

/*! Main window. */
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
    /*! Constructs the window and adds the childs widgets */
    explicit MainWindow();

    /*! Adds a collection given as XML string to the list view */
    void addCollection(const QString& xml);

private:
    QNetworkAccessManager networkAccessManager;
    ListViewWidget tableWidget;
    
    Playur::CollectionItemModel* model;
    Playur::CollectionItemModel* searchModel;

public slots:
    /*! Starts the collection fetch process with the given IP address */
    void fetchCollection(QString ip);

private slots:
    void openAddLibraryDialog();
    void readReply(QNetworkReply* reply);
    void applySearch(const QString& search);

};

#endif // MAINWINDOW_H
